/* SetupRank page controller */
(function () {
    'use strict';
    angular.module('module.business')
        .controller('RankQueryController', RankQueryController)
        .filter('auditStatusFilter', auditStatusFilter);

    RankQueryController.$inject = ['$rootScope', '$scope', '$http', '$state', '$uibModal', '$log', '$document', '$uibPosition', '$interval', '$q','i18nService'];

    function RankQueryController($rootScope, $scope, $http, $state, $uibModal, $log, $document, $uibPosition, $interval, $q,i18nService) {
        var vm = this;
        vm.activate = activate;                                           //页面初始化
        vm.viewRankInfo = viewRankInfo;
        vm.audits = audits;                                               //审核记录页面弹出方法
        vm.rankHigh= rankHigh;                                              //高级查询页面弹出方法
        vm.exportExcel = exportExcel;
        vm.selected = [];
        vm.gridOptions = {
            /* enableSorting: true,*/
            enableColumnResizing : true,//设置宽度
            multiSelect:true,                                           //多选
            enableRowSelection: true,                                  //允许选中行
            //showGridFooter:true,
            enableRowHeaderSelection:false,                           //允许通过点击行首选中行
            enableFullRowSelection:true,                              //允许通过点击行任意位置选中行
            modifierKeysToMultiSelect:true,                           //只允许通过键盘辅助多选(前提是允许多选)
            paginationPageSize: 10,
            paginationPageSizes: [10, 20, 50],
            enableGridMenu: true,
            columnDefs: [
                { field: 'ID',name:'序号', visible: true, width:'60',pinnedLeft:true},
                { field: 'RANKING_APPLY_NO', width:'170',name: '定级申请单号', cellTooltip: true, headerTooltip: true},
                { field: 'UNIT_NAME', name: '单位名称',cellTooltip: true, headerTooltip: true},
                { field: 'SYSTEM_NAME', name: '信息系统名称',cellTooltip: true, headerTooltip: true},
                { field: 'SYSTEM_LEVEL', name: '保护等级', cellTooltip: true, headerTooltip: true,width:'100'},
                { field: 'RANKING_APPLY_DATE', name: '定级申请时间',width:'150', cellTooltip: true, headerTooltip: true},
                { field: 'FORM_PERSON', name: '填报人', cellTooltip: true, headerTooltip: true,width:'100'},
                { field: 'TYPE', name: '类别', cellTooltip: true, headerTooltip: true,width:'80'},
                { field: 'AUDIT_STATUS', name: '审核状态',cellTooltip: true, headerTooltip: true,width:'90'},
                { field: 'AUDIT_RESULT', name: '审核结果', visible: true, cellTooltip: true, headerTooltip: true,width:'90'},
                { field: 'AUDIT_OPINION', name: '审核意见', visible: false, cellTooltip: true, headerTooltip: true},
                { field: 'RECORDING_STATUS', name: '备案状态', cellTooltip: true, headerTooltip: true,width:'90'}
            ]
        };
        i18nService.setCurrentLang('zh-cn');
        activate();

        return vm;

        /**
         * @description     页面初始化
         */
        function activate() {
            $scope.$on('$viewContentLoaded', function () {
                App.initAjax(); // initialize core components
            });

            $rootScope.settings.layout.pageContentWhite = true;
            $rootScope.settings.layout.pageBodySolid = true;
            $rootScope.settings.layout.pageSidebarClosed = false;
            $http.get('app/module/business/rank/query/data/query.json').then(function(data){
                console.log(data);
                vm.gridOptions.data = data.data;
            },function(data){

            });
        }
        /**
         * @description 打开查看弹窗
         */
        function viewRankInfo() {
            var modalInstance = $uibModal.open({
                animation: true,
                ariaLabelledBy: 'detail-modal-title',
                ariaDescribedBy: 'detail-modal-body',
                templateUrl: 'detail.html',
                controller: 'RankQueryDetailController',
                controllerAs: 'detail',
                size: 'lg'
            });
            modalInstance.result.then(function (selectedItem) {
            }, function () {
                vm.selected = [];
            });
        }
        /**
         * @description 打开查看弹窗
         */
        function exportExcel() {
            var modalInstance = $uibModal.open({
                animation: true,
                ariaLabelledBy: 'modal-title',
                ariaDescribedBy: 'modal-body',
                templateUrl: 'excel.html',
                controller: 'RankQueryExportExcelController',
                controllerAs: 'excel',
                size: 'md'
            });
            modalInstance.result.then(function (selectedItem) {
            }, function () {
                vm.selected = [];
            });
        }
        /**
         * @description 打开查看弹窗
         */
        function rankHigh() {
            var modalInstance = $uibModal.open({
                animation: true,
                ariaLabelledBy: 'modal-title',
                ariaDescribedBy: 'modal-body',
                templateUrl: 'high.html',
                controller: 'RankQueryHighController',
                controllerAs: 'rankHigh',
                size: 'lg'
            });
            modalInstance.result.then(function (selectedItem) {
            }, function () {
                vm.selected = [];
            });
        }
        /**
         * @description 打开审核记录弹窗
         */
        function audits() {
            var modalInstance = $uibModal.open({
                animation: true,
                ariaLabelledBy: 'modal-title',
                ariaDescribedBy: 'modal-body',
                templateUrl: 'audits.html',
                controller: 'RankQueryAuditsController',
                controllerAs: 'audits',
                size: 'lg'
            });
            modalInstance.result.then(function (selectedItem) {
            }, function () {
                vm.selected = [];
            });
        }
    }
    function auditStatusFilter() {
        var relationHash = {
            0: '草稿',
            1: '已受理',
            2: '审核中',
            3: '已审核'
        };
        return function(input) {
            if (!input){
                return '';
            } else {
                return relationHash[input];
            }
        };

    }
})();
